export const emojiList = [
    {
        content: '😀',
        rule: '[1]'
    },
    {
        content: '😉',
        rule: '[2]'
    },
    {
        content: '🥰',
        rule: '[3]'
    },
    {
        content: '🤑',
        rule: '[4]'
    },
    {
        content: '🤡',
        rule: '[5]'
    },
    {
        content: '🦞',
        rule: '[6]'
    },
    {
        content: '🐶',
        rule: '[7]'
    },
    {
        content: '🐷',
        rule: '[8]'
    },
    {
        content: '🌹',
        rule: '[9]'
    },
]

// 通过聊天记录匹配对应的表情包
export const stringToEmoji = (str) => {
    // 通过正则匹配到聊天记录中的表情
    return str.replace(/\[\d]/g, ($) => {
        const items = emojiList.find(v => v.rule === $)
        if (items) return items.content
        return $
    })
}

// 通过表情包转成rule
export const emojiToString = (str) => {
    // 拿到数组中所有的表情包
    const emoji = emojiList.map(v => v.content).join('|')
    // 通过表情包进行匹配
    const reg = new RegExp(emoji, 'g')
    return str.replace(reg, ($) => {
        const items = emojiList.find(v => v.content === $)
        // 如果匹配到就转换成rule
        if (items) return items.rule
        return $
    })
}